﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Apmis2._1.Models;

namespace Apmis2._1.Controllers
{
    public class PatientController : ApiController
    {
        private IPatientRepository _repo;
        public PatientController(IPatientRepository Repo)
        {
            _repo = Repo;
        }

        public IHttpActionResult Get()
        {
            var patients = _repo.GetPatients();
            return Ok(patients);
        }

        [HttpGet]
        [Route("api/patient/{pID:guid}")]
        public IHttpActionResult GetPatientbyPatientID(Guid pID)
        {
            var patients = _repo.GetPatientByID(pID);
            return Ok(patients);
        }

        
        public IHttpActionResult Post([FromBody]Patient newpatient)
        {
            if (_repo.addPatient(newpatient) &&
                _repo.save())
            {
                //return //Request.CreateResponse(HttpStatusCode.Created, newpatient);
                    //Created(System.uri,newPatient);

                return Created<Patient>(Request.RequestUri + newpatient.Id.ToString(), newpatient);
            }
                else
                {

                    return BadRequest();
                }

        }

        
    }
}
